<extend name="Base/common" />

<block name="style">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/Api/css/main.css">
</block>

<block name="Content">

<div class="page-group">
    <div class="page page-current">
        <div class="content native-scroll">
            <div class="register-info">
                <div class="content-padded">
                    <h1>{$banner['name']}</h1>
                    <h2>帮工小哥 <span>{$banner['name']|GetDateMk}</span></h2>
                    <p>{$banner['content']|htmlspecialchars_decode}</p>
                    
                    <if condition="$banner.activity eq '1'">
                    	<!-- 正在进行领取优惠券活动 -->
                    	
                    	<if condition="$user_id egt '1' AND empty($coupon)">
	                    	<div class="repair-num">
		                        <a href="#" onclick="coupon()">领取优惠券</a>
		                        <input type="hidden" name="random_num" id="random_num" value="{$banner['random']}"/>
		                        <input type="hidden" name="id" id="id" value="{$banner['banner_id']}"/>
		                    </div>
	                    <elseif condition="empty($user_id)"/>
	                    	<div class="repair-num">
	                        <a href="{:U('Public/login')}">登录领取优惠券</a>
	                    </div>
	                    </if>
                    <else/>
                    	<div class="repair-num">
	                        <a href="">赶快去注册吧</a>
	                    </div>
                    </if>
                </div>
            </div>
        </div>
    </div>
</div>

</block>

<block name="script">
<script type="text/javascript">

function coupon(){
	
	var randomNum = $("#random_num").val();
	var rid = $("#id").val();
	var target = Think.U('Activity/receiveCoupon');
	
	$.post(target, {'random_num':randomNum, 'rid':rid}, function(dataObj){
		
		if (dataObj.status == '-201') {
			$.confirm('身份认证已失效，请重新登录', function () {
		        var loginURL = Think.U('Public/login');
		        window.location.href = loginURL;
		        return false;
		    });
		}else if(dataObj.status == '-1' || dataObj.status == '0'){
			var msg = dataObj.status == '-1' ? '参数错误' : '操作失败';
			$.confirm(msg, function () {
				window.location.reload();
		        return false;
		    });
		}else if(dataObj.status == '1'){
			$.alert('优惠券领取成功', function () {
				window.location.reload();
		    });
		}
	});
}

</script>
</block>

